<?php

require_once("dao/forecast.dao.php");
require_once("dao/placeFromSql.dao.php");
require_once("storage/predefRoutes.php");
require_once("model/routeCollection.class.php");
require_once("model/route.class.php");
require_once("model/place.class.php");
require_once("model/forecast.class.php");

class predef extends abstract_controller {

	function prepare_model($request_params, Smarty $smarty_obj) {
		$smarty_obj->assign('page_title', 'TurYr: Predefinerte ruter');
		
		$id  = isset($_GET['id']) ? htmlentities($_GET['id'])  : "";
		
		$date = isset($_POST['date']) ? htmlentities($_POST['date']) : "";
		$hour = isset($_POST['time']) ? htmlentities($_POST['time']) : 12;		
		
		
		
		if (!empty($id)){
			
			$year  = date('Y');
			$month = date('m');
			$today = date('d');
			if (empty($date)){
				$hour  = date('H')+1;
				$date  = $year.'-'.$month.'-'.$today;
			}
		
			$xmlDate = $year.'-'.$month.'-'.$today.'T'.$hour.':00:00Z';
			
			$predefCollection = predefRoutes::getRoute($id,$xmlDate);
			
			
//			echo "<pre>"; 
//			foreach($predefCollection->getAllRoutes() as $route){
//				foreach ($route->getPlaceArray() as $place){
//					echo '<strong>'.$place->getName().'</strong><br/>';
//					print_r($place->getForecastArray());	
//				}			 
//			}
//			exit();
			


			$dateObj = functions::genereateDateObj($xmlDate);
			$smarty_obj->assign('date',$dateObj);
			$smarty_obj->assign('collection', $predefCollection);
			$smarty_obj->assign('ch_day', $date);
			$smarty_obj->assign('ch_time',$hour);
			
		}				
	}	
}

?>
